Skip to content

refactor(file-browser): Granular item rendering and programmatic DOM list construction - #2723

Open
AuDevTist1C wants to merge 3 commits into
Acode-Foundation:mainfrom
AuDevTist1C:refactor/fb-list-item
Open

refactor(file-browser): Granular item rendering and programmatic DOM list construction#2723
AuDevTist1C wants to merge 3 commits into
Acode-Foundation:mainfrom
AuDevTist1C:refactor/fb-list-item

Conversation

@AuDevTist1C

Copy link
Copy Markdown
Contributor

📌 Context & Motivation

Per #2500 (comment) regarding PR size and review complexity, this PR extracts the foundational DOM rendering refactor into a dedicated, self-contained pull request.

PR #2500 introduces navigation state management, skeleton UI feedback, and async safety routines. However, those additions directly depend on having granular DOM node control rather than compiling monolithic list templates. By isolating template scope reduction and DOM helper construction into this PR, we simplify code review and preserve Git history continuity before layering async navigation logic on top.


🛠️ Summary of Changes

This PR refactors directory list rendering in the file browser away from full-list Mustache template compilation into modular item construction helpers and programmatic DOM loops.

1. Continuous Git History Preservation

  • src/pages/fileBrowser/list.hbssrc/pages/fileBrowser/listItem.hbs: Isolated the file system rename operation into its own dedicated commit with zero content alterations. This ensures Git records a 100% similarity score, preserving continuous git blame and file history tracking across structural updates.

2. Template Scope Granularity (listItem.hbs)

  • Stripped the outer <ul class="list" id="list"> wrapper element and the surrounding {{#list}}...{{/list}} iteration tag from the Handlebars template.
  • Converted the file into a standalone row partial that accepts an entry object and renders a single <li> element representing an individual file or directory item.

3. DOM Construction Helpers (fileBrowser.js)

Implemented explicit helper utilities in fileBrowser.js to modularize node creation:

  • createListEl(): Generates and returns the parent <ul className="list" id="list"> container.
  • createListItemEl(obj): Renders item data via mustache.render(_listItem, obj) and parses the output into an HTMLLIElement node.
  • createPlaceholderEl(msg): Programmatically constructs dedicated empty-state nodes (<div id="placeholder">{msg}</div>).

4. Render Loop & Restored Empty State (fileBrowser.js)

  • Updated render(dir) to instantiate list containers programmatically and append rendered child elements via standard DOM iteration ($list.appendChild(el)).
  • Empty Directory Support: Previously, empty directory placeholders were managed via Mustache's built-in empty-msg attribute handling on the root list template. Under the new item-level workflow, explicit empty check logic was added: when list.length is zero, createPlaceholderEl(msg) appends the localized empty message element directly to the container.

5. Layout Alignment (fileBrowser.scss)

  • Defined CSS rules for #placeholder using Flexbox (display: flex, align-items: center, justify-content: center) to guarantee empty directory placeholder messages are centered vertically and horizontally within the file browser body.

🔍 Why Is This Refactor Necessary?

  1. Dependency for PR refactor(file-browser): Overhaul navigation state, skeleton rendering, and async safety  #2500: The PR requires direct, individual references to list item nodes and empty placeholder elements to implement skeleton loading states, transition effects(not yet implemented), and async state safety.
  2. Modular Architecture: Decoupling container generation from row template parsing eliminates full-template re-renders and provides granular control over dynamic DOM updates.
  3. Review Efficiency: Splitting this structural change into its own PR fulfills review guidelines by separating DOM manipulation updates from async navigation logic.

(PR name and description are AI generated (Gemini 3.6 Flash))

Isolate the file system rename operation into its own dedicated commit to preserve continuous history tracking within Git. Renaming `list.hbs` to `listItem.hbs` without altering any content ensures Git records this change as a 100% file rename. Decoupling this step prevents Git from misinterpreting subsequent structural template refactors as a destructive file deletion followed by the addition of an entirely new file.

* **Template File Rename (`src/pages/fileBrowser/`):**
* Renamed `src/pages/fileBrowser/list.hbs` to `src/pages/fileBrowser/listItem.hbs` with zero line changes (100% similarity score), guaranteeing clean `git blame` and file history continuity across structural revisions.

(AI generated commit message)
…eholder

Overhaul the directory rendering logic in the file browser by replacing monolithic template compilation with programmatic DOM element construction and individual item parsing.

Previously, directory list rendering relied on a single template (`list.hbs`) that wrapped the outer `<ul>` element, handled list iteration (`{{#list}}`), and relied on the `mustache` package's built-in capability to render placeholder text if the element had no children when the `empty-msg` HTML attribute was provided.

This commit refactors the template down to a granular single-item scale and adds the empty state placeholder back explicitly via programmatic rendering. By splitting template rendering into granular helper functions (`createListEl`, `createListItemEl`, and `createPlaceholderEl`), directory rendering now builds list elements individually and explicitly appends a styled placeholder node whenever a directory contains no files or folders.

* **Template Scope Reduction (`src/pages/fileBrowser/listItem.hbs`):**
* Removed the enclosing `<ul class="list" id="list">` container tag and the surrounding `{{#list}}...{{/list}}` iteration block from the Handlebars template.
* Converted the file into a standalone item partial that takes an entry object and produces a single `<li>` element representing a file or directory row.

* **DOM Element Construction Helpers (`src/pages/fileBrowser/fileBrowser.js`):**
* Added `createListEl()` to dynamically generate the parent `<ul className="list" id="list">` element.
* Added `createListItemEl(obj)` to parse individual item objects through `mustache.render(_listItem, obj)` into single `HTMLLIElement` nodes.
* Added `createPlaceholderEl(msg)` to create dedicated empty-state DOM elements (`<div id="placeholder">{msg}</div>`).

* **Render Loop & Empty State Logic (`src/pages/fileBrowser/fileBrowser.js`):**
* Updated `render(dir)` to construct list containers programmatically and append rendered child elements via standard DOM iteration (`$list.appendChild(el)`).
* Re-implemented empty directory handling: if `list.length` is zero, a placeholder element containing the localized empty folder string is appended to the list, restoring the empty message functionality previously supplied via Mustache's `empty-msg` attribute.

* **Placeholder Layout Styling (`src/pages/fileBrowser/fileBrowser.scss`):**
* Defined CSS rules for `#placeholder` utilizing Flexbox (`display: flex`, `align-items: center`, `justify-content: center`) to ensure empty folder messages are centered within the file browser container.

(AI generated commit message)
@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The file browser now constructs its list container and empty-state placeholder programmatically while rendering each directory entry from a standalone item template.

  • Replaces monolithic full-list Mustache rendering with per-item rendering and DOM appends.
  • Extracts the row markup into listItem.hbs.
  • Adds centered styling for the empty-directory placeholder.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/pages/fileBrowser/fileBrowser.js Refactors directory rendering into container, item, and placeholder helpers; the previously reported helper-name mismatch is fixed on current HEAD.
src/pages/fileBrowser/fileBrowser.scss Adds scoped flexbox layout rules that center the empty-directory placeholder.
src/pages/fileBrowser/listItem.hbs Preserves the existing directory-entry markup as a standalone single-item template.
src/pages/fileBrowser/list.hbs Removes the former full-list template after its row markup is moved to the granular item template.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Render["render(dir)"] --> List["createListEl()"]
  Render --> Check{"Directory has entries?"}
  Check -->|Yes| Item["createListItemEl(item)"]
  Item --> AppendItem["Append each LI to UL"]
  Check -->|No| Placeholder["createPlaceholderEl(message)"]
  Placeholder --> AppendPlaceholder["Append placeholder to UL"]
  AppendItem --> Mount["Replace existing list and mount UL"]
  AppendPlaceholder --> Mount
Loading

Reviews (3): Last reviewed commit: "fix" | Re-trigger Greptile

Comment thread src/pages/fileBrowser/fileBrowser.js Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@AuDevTist1C
AuDevTist1C marked this pull request as ready for review August 11, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant